﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Create.Master" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.Cemetery>" %>

<%@ Import Namespace="Common" %>
<%@ Import Namespace="Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CurentPlace" runat="server">
    墓穴管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="panel datagrid" style="width: auto;">
        <div class="panel-header">
            <div>
                选择园区： 
        <%=Html.DropDownListFor(model => model.Yuan,Models.SysFieldModels.GetArea("Area","Yuan"),"请选择")%>
                <select id="Pian" name="Pian">
                </select>
                <select id="Qu" name="Qu">
                </select>
            </div>
        </div>
        <div class="panel-body" style="height: 100%;">
            <div style="padding: 10px">
                <div id="btnGroup">
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addHao()">新增号</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="editPai()">修改排</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="editHao()">修改号</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="yanshou()">墓位验收</a>
                </div>
                <div class="bigdiv" style="display: none">
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.QuGuid) %>：
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.QuGuid) %>
                        <%: Html.ValidationMessageFor(model => model.QuGuid) %>
                    </div>
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Hao) %>：
                    </div>
                    <div class="editor-field">
                        <%: Html.TextBoxFor(model => model.Hao, new {  onkeyup = "isInt(this)", @class="text-box single-line" })%>
                        <%: Html.ValidationMessageFor(model => model.Hao) %>
                    </div>
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Pai) %>：
                    </div>
                    <div class="editor-field">
                        <%: Html.TextBoxFor(model => model.Pai, new {  onkeyup = "isInt(this)", @class="text-box single-line" })%>
                        <%: Html.ValidationMessageFor(model => model.Pai) %>
                    </div>
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.ShapeGuid) %>：
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.ShapeGuid) %>
                        <%: Html.ValidationMessageFor(model => model.ShapeGuid) %>
                    </div>
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Price) %>：
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Price) %>
                        <%: Html.ValidationMessageFor(model => model.Price) %>
                    </div>
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.IsYanShou) %>：
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.IsYanShou) %>
                        <%: Html.ValidationMessageFor(model => model.IsYanShou) %>
                    </div>
                </div>
                <div id="CemeteryStr">
                </div>

            </div>
        </div>

    </div>



    <div>
        <div id="dlg" class="easyui-dialog" title="新增排号" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        createCemetery();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#dlg').dialog('close');
                    }
                }]
            ">

            <table>
                <tr>
                    <td>排名称:</td>
                    <td>
                        <input id="painame" class="textbox" type="text" name="name" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>排序号:</td>
                    <td>
                        <input id="paisort" class="easyui-numberbox" type="text" name="sort" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>开始号:</td>
                    <td>
                        <input id="startno" class="easyui-numberbox" type="text" name="start" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>结束号:</td>
                    <td>
                        <input id="endno" class=" easyui-numberbox" type="text" name="end" data-options="required:true" />
                    </td>
                </tr>

                <tr>
                    <td>选择墓型:</td>
                    <td>
                        <select id="muxing"></select>
                    </td>
                </tr>


            </table>

        </div>

        <div id="addhao" class="easyui-dialog" title="新增号" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        createhao();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#addhao').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>排名称:</td>
                    <td>
                        <select id="haopainame">
                        </select>
                    </td>
                </tr>

                <tr>
                    <td>开始号:</td>
                    <td>
                        <input id="haostartno" class="easyui-numberbox" type="text" name="start" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>结束号:</td>
                    <td>
                        <input id="haoendno" class=" easyui-numberbox" type="text" name="end" data-options="required:true" />
                    </td>
                </tr>
            </table>

        </div>

        <div id="editPai" class="easyui-dialog" title="修改排" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        editpaisave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#editPai').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>排名称:</td>
                    <td>
                        <select id="editpaipainame">
                        </select>
                    </td>
                </tr>


            </table>

        </div>
        <div id="editHao" class="easyui-dialog" title="修改号" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        edithaosave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#editHao').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>号:</td>
                    <td>
                        <input id="haono" class=" easyui-numberbox" type="text" name="haono" data-options="required:true" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="yanshou" class="easyui-dialog" title="墓位验收" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        yanshousave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#yanshou').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>是否合格:</td>
                    <td>
                        <select id="selyanshou">
                            <option value="合格" selected="selected">合格</option>
                            <option value="不合格">不合格</option>
                        </select>
                    </td>
                </tr>


            </table>

        </div>
    </div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <style>
        ul {
            clear: both;
        }

        li {
            float: left;
            list-style-type: none;
            width: 60px;
            text-align: center;
            height: 90px;
        }
    </style>
    <script type="text/javascript">

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        $(function () {
            getPian("#Pian");
            $("#Yuan").change(function () { getPian("#Pian"); });

            getQu("#Qu");
            $("#Pian").change(function () { getQu("#Qu"); });

            $('#dlg').dialog('close');
            $('#addhao').dialog('close');
            $('#editPai').dialog('close');
            $('#editHao').dialog('close');
            $('#yanshou').dialog('close');
            $("#Qu").change(function () {
                $("#QuGuid").val($("#Qu").val());

                GetCemeteryString();
            });
            var aaa = getQueryString('isdanmu');
             //是弹幕定价过来的。
            if (aaa == "1") {
                $('#btnGroup').html('<a href="#" class="easyui-linkbutton l-btn" data-options="iconCls:\'icon-add\'" id="addCemetery" onclick="danmudingjia()"><span class="l-btn-left"><span class="l-btn-text icon-add l-btn-icon-left">单墓定价</span></span></a>');
            } else {
                var iframeid = window.parent.$('#tabs').tabs('getSelected').find('iframe').attr("id");
                $.getJSON("../Home/GetToolbar", { id: iframeid }, function (data) {
                    if (data == null) {
                        return;
                    } else {
                        $.each(data, function (i, item) {
                            var btnstr = '<a href="#" class="easyui-linkbutton l-btn" data-options="iconCls:\'' + item.iconCls + '\'" id="addCemetery" onclick="' + item.handler + '()"><span class="l-btn-left"><span class="l-btn-text icon-add l-btn-icon-left">' + item.text + '</span></span></a>';
                            $('#btnGroup').html($('#btnGroup').html() + btnstr);
                        });
                    }
                });
            }
        });
        function getPian(Pian) {
            $(Pian).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Pian));
            bindAreaDropDownList(Pian, "#Yuan");
            $(Pian).change();
        }

        function getQu(Qu) {
            $(Qu).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Qu));
            bindAreaDropDownList(Qu, "#Pian");
            $(Qu).change();
        }


        function bindAreaDropDownList(id, parentid) {

            if ($(parentid).val() != "") {

                var url = "../Home/GetAreaByParent";
                $.ajaxSetup({ cache: false });
                $.getJSON(url, { id: id.substring(1), parentid: parentid.substring(1), value: $(parentid).val() }, function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["Value"])
                            .text(item["Text"])
                            .appendTo($(id));
                    });
                });
            }
        }
        function addpai() {
            var quguid = $('#QuGuid').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }
            $('#muxing').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#muxing'));
            var url = "../Shape/GetMuXing";
            $.ajax({
                url: url,
                type: "Post",

                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["Value"])
                            .text(item["Text"])
                            .appendTo($('#muxing'));
                    });
                }
            });

            $('#dlg').dialog('open');
        }

        function deleteselected() {
            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            $.messager.confirm('操作提示', "确认删除这 " + count + " 项吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/Delete", { query: arr.join(",") }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '删除成功!', 'info');
                            GetCemeteryString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        }
        function addHao() {
            var quguid = $('#QuGuid').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }
            $('#haopainame').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#haopainame'));
            var url = "../Cemetery/GetPai";
            $.ajax({
                url: url,
                type: "Post",
                data: { quguid: quguid },
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item.Pai)
                            .text(item.PaiName)
                            .appendTo($('#haopainame'));
                    });
                }
            });

            $('#addhao').dialog('open');
        }

        function editPai() {
            var quguid = $('#QuGuid').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#editpaipainame').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#editpaipainame'));
            var url = "../Cemetery/GetPai";
            $.ajax({
                url: url,
                type: "Post",
                data: { quguid: quguid },
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item.Pai)
                            .text(item.PaiName)
                            .appendTo($('#editpaipainame'));
                    });
                }
            });

            $('#editPai').dialog('open');
        }

        function editHao() {
            var quguid = $('#QuGuid').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#editHao').dialog('open');
        }
        function yanshou() {
            var quguid = $('#QuGuid').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#yanshou').dialog('open');
        }
        

        function createCemetery() {
            var painame = $('#painame').val();
            var paisort = $('#paisort').val();
            var startno = $('#startno').val();
            var endno = $('#endno').val();
            var muxing = $('#muxing').val();
            if (painame == "") {
                alert("排名称不能为空");
                return;
            }
            if (paisort == "") {
                alert("排序号不能为空");
                return;
            }
            if (startno == "") {
                alert("开始号不能为空");
                return;
            }
            if (endno == "") {
                alert("结束号不能为空");
                return;
            }
            if (muxing == "") {
                alert("墓型不能为空");
                return;
            }

            $.ajax({
                url: "../Cemetery/CreateCemetery",
                type: "Post",
                data: { quguid: $('#QuGuid').val(), painame: painame, paisort: paisort, startno: startno, endno: endno, muxing: muxing },
                dataType: "json",
                success: function (data) {

                    alert(data);
                    GetCemeteryString();
                    $('#dlg').dialog('close');
                }
            });

        }
        function createhao() {
            var haopainame = $('#haopainame  option:selected').text();
            var haopaisort = $('#haopainame').val();
            var haostartno = $('#haostartno').val();
            var haoendno = $('#haoendno').val();

            if (haopainame == "") {
                alert("排名称不能为空");
                return;
            }

            if (haostartno == "") {
                alert("开始号不能为空");
                return;
            }
            if (haoendno == "") {
                alert("结束号不能为空");
                return;
            }

            $.ajax({
                url: "../Cemetery/CreateHao",
                type: "Post",
                data: { quguid: $('#QuGuid').val(), haopainame: haopainame, haopaisort: haopaisort, haostartno: haostartno, haoendno: haoendno },
                dataType: "json",
                success: function (data) {

                    alert(data);
                    GetCemeteryString();
                    $('#addhao').dialog('close');
                }
            });

        }
        function editpaisave() {
            var painame = $('#editpaipainame  option:selected').text();
            var paisort = $('#editpaipainame').val();


            var editpaipainame = $('#editpaipainame').val();
            if (editpaipainame == "") {
                alert("排名称不能为空");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            $.messager.confirm('操作提示', "确认修改这 " + count + " 项的排号吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/EditPai", { query: arr.join(","), painame: painame, paisort: paisort, quguid: $('#QuGuid').val() }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '修改排号成功!', 'info');
                            $('#editPai').dialog('close');
                            GetCemeteryString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '修改排号失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });


        }

        function edithaosave() {
            var editHao = $('#haono').val();
            if (editHao == "") {
                alert("号不能为空");
                return;
            }
            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }
            });
            $.messager.confirm('操作提示', "确认修改这 " + count + " 项的号吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/EditHao", { query: arr.join(","), edithao: editHao }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '修改号成功!', 'info');
                            $('#editHao').dialog('close');
                            GetCemeteryString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '修改号失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });
        }

        function yanshousave() {
            var yanshou = $('#selyanshou').val();
             
            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }
            });
            $.messager.confirm('操作提示', "确认验收这 " + count + " 项墓位吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/YanShou", { query: arr.join(","), yanshou: yanshou }, function (res) {
                        if (res == "OK") {
                            
                            $.messager.alert('操作提示', '验收成功!', 'info');
                            $('#yanshou').dialog('close');
                            GetCemeteryString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '验收失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });
        }
        
        function GetCemeteryString() {
            $.ajax({
                url: "../Cemetery/GetCemeteryString",
                type: "Post",
                data: { quguid: $('#QuGuid').val() },
                dataType: "json",
                success: function (data) {

                    $('#CemeteryStr').html(data);
                    $("input[ id^='cemetery'][type= 'checkbox']").change(function () {
                        var name = $(this).attr("name");
                        if ($(this).attr("checked")) {
                            $("input[name='" + name + "']").attr("checked", true);
                        } else {
                            $("input[name='" + name + "']").attr("checked", false);
                        }
                    });
                }
            });
        }
    </script>
</asp:Content>

